package utils

import (
	"fmt"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
	sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20190711" //引入sms
)

type Mobile struct {
	Mobile     string   // 要发送的手机号
	TemplateId string   // 短信模板id
	Params     []string // 模板参数
}

func NewMobile(mobile, templateId string, params []string) *Mobile {
	return &Mobile{
		Mobile:     mobile,
		TemplateId: templateId,
		Params:     params,
	}
}

// 发送短信
func (m *Mobile) SendSms() error {
	credential := common.NewCredential(
		"AKIDg7IC5jvvg5ylJdxmyt34rNcdQyI77F2a",
		"CCwPSEk0hFYptxuVsSUJx7LejX3KygHp",
	)
	cpf := profile.NewClientProfile()
	client, _ := sms.NewClient(credential, "ap-guangzhou", cpf)
	request := sms.NewSendSmsRequest()
	request.SmsSdkAppid = common.StringPtr("1400461575")
	request.Sign = common.StringPtr("北京踏踏实实教育科技")
	request.TemplateID = common.StringPtr(m.TemplateId)
	request.TemplateParamSet = common.StringPtrs(m.Params)
	request.PhoneNumberSet = common.StringPtrs([]string{fmt.Sprintf("+86%s", m.Mobile)})
	_, err := client.SendSms(request)
	if err != nil {
		return err
	}
	return nil
}
